package core.online;

import java.util.LinkedList;
import java.util.Queue;

import net.Packet;

/**
 * Stores packets for the future.
 * 
 * @author Jason
 * 
 */

public class CommandBank {

	private final int BUFFER_SIZE = 16;

	@SuppressWarnings("unchecked")
	private final Queue<Packet>[] storage = new LinkedList[BUFFER_SIZE];

	public CommandBank() {
		for (int i = 0; i < storage.length; i++) {
			storage[i] = new LinkedList<Packet>();
		}
	}

	/**
	 * Adds a packet to be read in the specified frame.
	 */
	public void add(Packet packet, int frame) {
		storage[frame % BUFFER_SIZE].add(packet);
	}

	/**
	 * Gets all packets stored for the given frame.
	 */
	public Queue<Packet> getCommandsFor(int frame) {
		return storage[frame % BUFFER_SIZE];
	}

}
